import 'package:flustars/flustars.dart';
import 'package:flutter/material.dart';
import 'package:flutter/physics.dart';
import 'package:flutter/services.dart';
import 'package:flutter_app_open_camera/constant/Constants.dart';
import 'package:flutter_app_open_camera/page/login_page.dart';
import 'package:flutter_app_open_camera/page/main_page.dart';
import 'package:flutter_app_open_camera/page/splash_page.dart';
import 'package:flutter_app_open_camera/provider/count_provider.dart';
import 'package:flutter_app_open_camera/resource/strings/resource_string.dart';
import 'package:flutter_app_open_camera/resource/theme/dark_mode_provider.dart';
import 'package:flutter_localizations/flutter_localizations.dart';
import 'package:flutter_screenutil/screenutil_init.dart';
import 'package:provider/provider.dart';
import 'package:pull_to_refresh/pull_to_refresh.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'base/base_container.dart';

void main() {
  runApp(MyApp());
  SystemUiOverlayStyle systemUiOverlayStyle =
      SystemUiOverlayStyle(statusBarColor: Colors.transparent);
  SystemChrome.setSystemUIOverlayStyle(systemUiOverlayStyle);
}

// ignore: must_be_immutable
class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    SystemChrome.setPreferredOrientations([
      DeviceOrientation.portraitUp, //只能纵向
    ]);
    //初始化适配
    return ScreenUtilInit(
        designSize: Size(375, 812),
        allowFontScaling: false,
        builder: () => MultiProvider(
              providers: [
                ChangeNotifierProvider.value(value: DarkModeProvider()),
                ChangeNotifierProvider.value(value: CountProvider()),
              ],
              child: Consumer<DarkModeProvider>(
                  builder: (context, darkModeProvider, _) {
                return RefreshConfiguration(
                  headerBuilder: () => MaterialClassicHeader(),
                  // Configure the default header indicator. If you have the same header indicator for each page, you need to set this
                  footerBuilder: () => ClassicFooter(
                    loadStyle: LoadStyle.ShowWhenLoading,
                  ),
                  // Configure default bottom indicator
                  headerTriggerDistance: 80.0,
                  // header trigger refresh trigger distance
                  springDescription:
                      SpringDescription(stiffness: 170, damping: 16, mass: 1.9),
                  // custom spring back animate,the props meaning see the flutter api
                  maxOverScrollExtent: 50.h,
                  //The maximum dragging range of the head. Set this property if a rush out of the view area occurs
                  maxUnderScrollExtent: 50.h,
                  // Maximum dragging range at the bottom
                  enableScrollWhenRefreshCompleted: true,
                  //This property is incompatible with PageView and TabBarView. If you need TabBarView to slide left and right, you need to set it to true.
                  enableLoadingWhenFailed: true,
                  //In the case of load failure, users can still trigger more loads by gesture pull-up.
                  hideFooterWhenNotFull: false,
                  // Disable pull-up to load more functionality when Viewport is less than one screen
                  enableBallisticLoad: false,
                  // trigger load more by BallisticScrollActivity
                  autoLoad: true,
                  child: MaterialApp(
                    theme: new ThemeData(
                        primarySwatch: Colors.blue,
                        highlightColor: Colors.transparent,
                        splashColor: Colors.transparent,
                        platform: TargetPlatform.iOS //添加这个属性即可
                        ),
                    localizationsDelegates: [
                      const DemoLocalizationsDelegate(),
                      GlobalMaterialLocalizations.delegate,
                      GlobalWidgetsLocalizations.delegate,
                      RefreshLocalizations.delegate,
                    ],
                    supportedLocales: [
                      const Locale('en', ''),
                      const Locale('zh', ''),
                    ],
                    home: SpUtil.getBool(Constants.IS_REALNAME, defValue: true)
                        ? MainPage()
                        : LoginPage(),
                  ),
                );
              }),
            ));
  }
}
